package com.tz.yiqingapp.controller.admin;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tz.yiqingapp.bean.Admin;
import com.tz.yiqingapp.bean.Spiderlog;
import com.tz.yiqingapp.config.AccessLimit;
import com.tz.yiqingapp.dto.PageDTO;
import com.tz.yiqingapp.mapper.AdminMapper;
import com.tz.yiqingapp.mapper.SpiderMapper;
import com.tz.yiqingapp.utils.MyPasswordEncoder;
import com.tz.yiqingapp.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;

@RestController
@Slf4j
@RequestMapping("/admin")
public class AdminSpider {

    @Autowired
    AdminMapper adminMapper;
    @Autowired
    SpiderMapper spiderMapper;

    @AccessLimit(times = 5)
    @PostMapping("/getspiderhistory")
    @ResponseBody
    public HashMap<String,Object> getDashboardInfo (@RequestBody PageDTO pageDTO, HttpServletRequest request) {

        System.out.println("sessionid :" + request.getSession().getId());
        if(request.getSession().getAttribute("loginrole") == null ||
                !request.getSession().getAttribute("loginrole").equals("admin")){
            return ResponseUtils.notlogin("not login");
        }
        Page<Spiderlog> spiderlogPage = new Page<>(pageDTO.getCurrentpage() , pageDTO.getPagesize());
        IPage<Spiderlog> spiderlogIPage = spiderMapper.selectPage(spiderlogPage , null);

        return ResponseUtils.successlist(
                spiderlogIPage.getTotal(),
                spiderlogIPage.getPages(),
                spiderlogIPage.getCurrent(),
                spiderlogIPage.getRecords());
    }
}
